package com.yys.apm.common.response;


import com.yys.apm.common.enums.ErrorType;

/**
 * 返回封装
 *
 * @author Yingsheng Ye
 */
public class Response<T> {

    private int code = ErrorType.SUCCESS.getCode();

    private String message;

    private T data;

    public static Response<String> success() {
        return new Response<>();
    }

    public static <E> Response<E> success(E e) {
        return new Response<>(e);
    }

    public static Response<String> failed(String msg) {
        return new Response<>(ErrorType.ERROR.getCode(), msg);
    }

    public static Response<String> failed(int code, String msg) {
        return new Response<>(code, msg);
    }

    public Response() {

    }

    public Response(T data) {
        this.data = data;
    }

    public Response(int code, String message) {
        this.code = code;
        this.message = message;
    }

    public Response(int code, String message, T data) {

        this.code = code;

        this.message = message;

        this.data = data;

    }

    public Response(T data, ErrorType errorType) {

        this.code = errorType.getCode();

        this.message = errorType.getMessage();

        this.data = data;

    }

    public Response(ErrorType errorType) {

        this.code = errorType.getCode();

        this.message = errorType.getMessage();

    }

    public int getCode() {

        return code;

    }

    public void setCode(int code) {

        this.code = code;

    }

    public String getMessage() {

        return message;

    }

    public void setMessage(String message) {

        this.message = message;

    }

    public T getData() {

        return data;

    }

    public void setData(T data) {

        this.data = data;

    }

    @Override
    public String toString() {
        return "Response{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
